<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>意达设计</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/member.css"/>

</head>
<body class="body">

<!-- header -->
<div class="pageheader"><a href="javascript:void(0);" onclick="api.closeWin();" class="return"></a><span>购物车</span></div>

<!-- contact -->
<div class="shoche">
    <ul id='con'>

        <!-- <li>
            <div class="chebox"><label><input type="checkbox" class="dnckbox" name=""></label></div>
            <div class="cheimg"><img src="../image/page/img-028.jpg"></div>
            <div class="checont">
                <div class="chet1">金狐狸包包女手提包</div>
                <div class="chet2">颜色：红色</div>
                <div class="numch">
                    <div class="chenum">￥<span data="150.00">150.00</span></div>
                    <div class="calcu">
                        <a href="javascript:void(0)" class="chejs"></a>
                        <span>1</span>
                        <a href="javascript:void(0)" class="chezj"></a>
                    </div>
                </div>
            </div>
        </li>
         -->
    </ul>
</div>


<div class="sumeNull"></div>
<div class="cheft">
    <label>全选<input type="checkbox" class="allchebox" name=""></label>
    <div class="allnums">合计：<em>¥</em><span id='total'>0.00</span></div>
    <input type="button" class="cheBtn" value="提交订单" onclick="tijiao();" />
</div>



<div class="frameBox">
    <div class="frameCnt">
        <div class="ftit">
            <div class="ftoall">
                <div class="ftit_l"></div>
                
                <div class="closeframe"></div>
            </div>
            <div class="numbs" style="margin-top: 0; border-top: none;" id='showjxs'>
                <div class="numbs_l">选择经销商</div>
                <div class="numbs_r" style="display: flex; align-items: center;"><span style="width: auto; padding-right: .1rem" id='jxs' data-id="0"></span><i style="display: block;
                                               width: .2rem;
                                               height: .2rem;
                                               background: url(../image/icon/icon-029.png) no-repeat center;
                                               background-size: .1rem;"  onclick="choosejxs()"></i></div>
            </div>
           
            <div class="peson">配送至<span>(配送地可能会影响库存，请正确选择)</span></div>
            <div class="fmaddres">
                <a href="#"><span  data-id="0" id='addr'>请选择地址</span><i onclick="chooseaddr()"></i></a>
            </div>
        </div>
        <div class="feombtn"><input type="button" value="确定" onclick='chooseover()'></div>
    </div>
</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/adaptive.js"></script>
<script type="text/javascript" src="../script/tabs.js"></script>
<script type="text/javascript">
    window['adaptive'].desinWidth = 750;
    window['adaptive'].baseFont = 28;
    window['adaptive'].maxWidth = 750;
    window['adaptive'].init();

    

    
    apiready = function () {
        $api.fixStatusBar($api.dom('.header'));
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            api.closeWidget();
        });
        api.showProgress();

        if(isvip==2){
            $('#showjxs').show();
        }else{
            $('#showjxs').hide();
        }

        var para=api.pageParam;
        

        

        toDoRequest(0,0);


        if(para.aid>0 || para.jid>0){
            info();
        }

        
    };


    
 
  function jian(id){
    toDoRequest(1,id);
  }
   function jia(id){
    toDoRequest(2,id);
  }
  

    
  function toDoRequest(type,id){

        var p={token:token,type:type,id:id};

        api.ajax({
            url: webSiteUrl+'/app/user/mycart',
            method: 'post',
            data: {
                values:p,
            }
        }, function(ret, err) {
            api.hideProgress();
            
            if(ret.code==200){
                
                //alert(ret.msg);
              
                html = "";
                var tj=ret.data.data;
               
                
for(var i=0;i<tj.length;i++){

html+='<li><div class="chebox"><label><input type="checkbox" checked="true" class="dnckbox"  data-id="'+tj[i].id+'" ></label></div><div class="cheimg"><img src="'+webSiteUrl+tj[i].icon+'"></div><div class="checont"><div class="chet1">'+tj[i].name+'</div><div class="chet2">颜色：'+tj[i].color+'</div><div class="numch"><div class="chenum">￥<span data="150.00">'+tj[i].money+'</span></div><div class="calcu"><a href="javascript:void(0)" class="chejs" onclick="jian('+tj[i].id+')"></a><span>'+tj[i].num+'</span><a href="javascript:void(0)" class="chezj" onclick="jia('+tj[i].id+')"></a></div></div></div></li>';
}

               
                $('#con').html(html);
                $('#total').html(ret.data.total);
            }else{
                //alert(ret.msg)
            }

        });
    }
    


    function tijiao () {
        $(".frameBox").show();return;
        
        
    }
    function info(){
        var jxsid=$api.getStorage('jxsid');
          var jxstxt=$api.getStorage('jxstxt');

        $('#jxs').attr('data-id',jxsid);
        $('#jxs').html(jxstxt);

        var addrid=$api.getStorage('addrid');
          var addrtxt=$api.getStorage('addrtxt');
                $('#addr').attr('data-id',addrid);
                $('#addr').html(addrtxt);

                $(".frameBox").show();
        

      
    }

    function choosejxs () {
        api.openWin({
            name: 'shopName',
            url: './myuser.html',
            pageParam: {
                type:'cartuser',
            }
        });
    }

    function chooseaddr () {
        //$api.setStorage('cartaddr',1);
        api.openWin({
            name: 'shopName',
            url: './myaddr.html',
            pageParam: {
                type:'cartaddr',
            }
        });
    }
    
    function chooseover () {
        var addrid=$('#addr').attr('data-id');
       

        if(isvip==2){
            var jid=$('#jxs').attr('data-id');
            if(jid==0){
                alert('请选择经销商');$(".frameBox").show();return;
            }
        }else{
             var jid=0;
        }
       
        if(addrid==0){
            alert('请选择地址');$(".frameBox").show();return;
        }


        var chk='';

        $(".dnckbox:checked").each(function() {
            var id=$(this).attr('data-id');
            if(chk==''){
                chk+=id;
            }else{
                chk+=','+id;
            }
            
        });
        
        if(chk==''){
            alert('请选择商品');return;
        }
        
        p={token:token,ids:chk,addrid:addrid,jid:jid};
        //alert(JSON.stringify(p));
        api.ajax({
            url: webSiteUrl+'/app/user/cartorder',
            method: 'post',
            data: {
                values:p,
            }
        }, function(ret, err) {
            api.hideProgress();
            
            if(ret.code==200){
                api.openWin({
                    name: 'selectaddName',
                    url: './myorder.html',
                    pageParam: {
                        ids: chk,
                        type:1,
                    }
                });
            }else{
                alert(ret.msg);
            }
        });    
                
        
    } 

    $(".cheft label").addClass('cellOn');
    $(".dnckbox").prop('checked', 'checked');
    $(".chebox").addClass('cheboxOn');
    sunPlay();
    $(".shoche ul li").addClass("ston");
    function sunPlay(){
        var sumMore=0;
        for(var i=0;i<$(".shoche ul li").length;i++){
            sumMore += parseFloat($(".shoche ul li").find(".chenum span").get(i).innerHTML);
        }
        var s = parseFloat(sumMore).toFixed(2);
        $(".allnums span").html(s);
    }
</script>

</html>
